#include <myheader_c_plus.h>
using namespace std;
int main(int argc, char *argv[])
{
    vector<int> a;
    int val = 11;
    for(int i = 0; i < 10; i++){
        a.push_back(i);
    }

    //find
    for(auto it = a.cbegin(); it != a.cend(); it++){
        cout << *it << " ";
    }
    cout << endl;
    auto res = find(a.cbegin(),a.cend(),val);
    const type_info& type = typeid(res);
    cout << type.name() << endl;
    if(res == a.cend()){
        cout << "the val : " << val << " is not in the vector" << endl;
    }else{
        cout << "the val is in the vector" << endl;
    }
    cout << endl;
    
    //accumulate
    int sum = 0;
    sum = accumulate(a.cbegin(),a.cend(),0);
    cout << sum << endl;

    //multiply 2 each element(the difference between the cbegin() and begin())
    for(auto it = a.begin(); it != a.end(); it++){
        cout << *it << " ";
        *it *= 2;
    }
    cout << endl;
    int second_sum = accumulate(a.cbegin(),a.cend(),0);
    cout << "after multiply 2 the sum  = " << second_sum << endl;

    //reverse the output
    for(auto it = a.rbegin(); it != a.rend(); it ++){
        cout << *it << " ";
    }
    cout << endl;


    //string
    vector<string> string_vec;
        string_vec.push_back("hello");
        string_vec.push_back("world");
        string_vec.push_back("how");
        string_vec.push_back("are");
        string_vec.push_back("you");
        string_vec.push_back("thanks");

    //find int string
    auto it = find(string_vec.cbegin(), string_vec.cend(),"world");
    if(it != string_vec.cend()){
        cout << "find the \"world\" in the sting_vec" << endl;
    }else{
        cout << "cant find the string in the vec" << endl;
    }
        
    //accumulate in string 
    string acc_str;
    acc_str = accumulate(string_vec.cbegin(),string_vec.cend(),string(""));
    cout << acc_str << endl;

    //generic algorithm in queue
    queue<int, list<int>> que;
    que.push(1);
    que.push(2);
    que.push(6);
    que.push(4);
    cout << que.front() << endl;
    que.pop();
    
    //equal:vec2 must bigger than vec1 or 
    //there will be a undefine beheave occurs
    vector<int> vec1,vec2;
    vec1.push_back(1);
    vec1.push_back(2);
    vec1.push_back(3);


    vec2.push_back(1);
    vec2.push_back(2);
    vec2.push_back(3);
    vec2.push_back(4);
    if(equal(vec1.cbegin(),vec1.cend(),vec2.cbegin())){
        cout << "equal" <<endl;
    }else{
        cout << "not equal" << endl;
    }

    //fill fill_n and back_inserter
    vector<int> vec3;
    auto it2 = back_inserter(vec3);
    //fill the first ten elements of vec3 by 1
    fill_n(it2,10,1);
    int cnt = count(vec3.cbegin(),vec3.cend(),1);
    cout << "there are " << cnt <<"elements that equal 1" << endl; 
    //fill last five elements by 3
    fill_n(it2,5,3);
    for(auto it = vec3.begin(); it != vec3.end(); it++){
        cout << *it << "  ";
    }
    cout << endl;
    //fill elements through the writen iterator
    fill(vec3.begin() + 3, vec3.end() - 2, 4);

    for(auto it = vec3.begin(); it != vec3.end(); it++){
        cout << *it << "  ";
    }
    cout << endl;

    //sort
    sort(string_vec.cbegin(),string_vec.cend());
    
    for(auto it = string_vec.begin(); it != string_vec.end(); it++){
        cout << *it << "  ";
    }
    return 0;
}

